package com.baidu.io;

import java.io.BufferedReader;
import java.io.FileReader;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.Statement;

public class D08_ReadLineDemo {
    public static void main(String[] args) throws Exception {
        String url = "jdbc:mysql://10.177.71.109:10072/position_match?useUnicode=true&characterEncoding=UTF-8&useSSL=false&serverTimezone=UTC";
        String user = "position_match";
        String password = "PositionMatch220621";
        String driver = "com.mysql.cj.jdbc.Driver";

        Class.forName(driver);
        Connection connection = DriverManager.getConnection(url, user, password);
        Statement statement = connection.createStatement();


        FileReader fileReader = new FileReader("/Users/yuanfeng02/work/联通-点面匹配项目/文档/bd84province0322.csv");
        BufferedReader bufferedReader = new BufferedReader(fileReader);

        String line = null;
        while (null != (line = bufferedReader.readLine())){
            String[] split = line.split("\t");
            double leg = (double)split[0].length()/1048576;
            System.out.println(String.format("%.2f", leg) + " " + split[2].length() + " " + split[2]);
            String sql = "insert into `province_wkt_list`(procode,proname,wkt) values ('" + split[1] + "','" + split[2] + "','" + split[0] + "')";
            System.out.println(statement.execute(sql));
        }

        bufferedReader.close();
        fileReader.close();
        connection.close();

    }
}
